<template>
	<view class="v-home-page" :style="{ '--bg-image': `url(${ materialBg})` }" v-if="uid">
		<view :style="{ height: navTop + 'px' }"></view>
		<view id="barTitle" :style="{ opacity: opacityStyle, height: heightSystemss+Number(70) + 'px' }"
			v-show="!hiddenModel">
			<text>任务列表</text>
		</view>
		

		<view class="flex-start-center " style="color:#333333" @click="navBack()">

			<uni-icons style="margin-top: 7rpx;font-weight: 700;" color="#333333" type="left" size="20"></uni-icons>
			<text style="color: 333333;font-size: 33rpx;font-weight: 700;"> 任务列表</text>
		</view>
		<view class="search-content flex-start-center ">
				
					<uni-icons style="margin-left: 20rpx;" color="#00000048" type="search" size="24"></uni-icons>
				
					
					<input placeholder="请输入搜索内容" v-model="name" @input="changeInput" 
						style="line-height: 1em; " placeholder-style="font-size:28rpx;color:#A1A1A1;" />
				
				
			</view>
		<view class="taskStatistics flex-between">
			<view class="flex-column">
				<view class="" style="color: #0184F0;font-weight: bold;font-size: 32rpx;">
					{{taskStatis.allCount}}
				</view>
				<view class="margin-top_16rpx">
					总任务数量
				</view>
			</view>
			<view class="flex-column">
				<view class="" style="color: #0184F0;font-weight: bold;font-size: 32rpx;">
					{{taskStatis.otherCount}}
				</view>
				<view class="" class="margin-top_16rpx ">
					待剪辑数量
				</view>
			</view>
			<view class="flex-column">
				<view class="" style="color: #0184F0;font-weight: bold;font-size: 32rpx;">
					{{taskStatis.finishCount}}
				</view>
				<view class="" class="margin-top_16rpx">
					完成数量
				</view>
			</view>
			<view class="flex-column">
				<view class="" style="color: #0184F0;font-weight: bold;font-size: 32rpx;">
					{{taskStatis.subCount}}
				</view>
				<view class="" class="margin-top_16rpx">
					作品数量
				</view>
			</view>
		</view>

		<view class="tabsPosition margin-top_30rpx">
			<v-tabs v-model="cIndex" :tabs="tabs" bgColor="transparent" activeColor="#386EFF" @change="e=>changeTab(e)"
				fontSize="28rpx"></v-tabs>

		</view>
		<mescroll-body ref="mescrollRef" :height="windowHeight+'rpx'" @init="mescrollInit" @down="downCallback"
			@up="upCallback" :up="upOption" :down="downOption">

			<view class="hotSellingList" v-for="(item,index) in list" :key="index">
				<view class="font-overflow" style="width: 566rpx;font-size: 32rpx;">
					{{item.name}}
				</view>
				<view class="flex-start-center margin-top_16rpx padding-bottom_40rpx border-bottom-ECECEC">

					<view class="" style="color: #999999;">
						创建时间：{{item.create_time}}
					</view>
				</view>
				<view class="flex-between" style="padding: 30rpx 0rpx 0;">
					<view class="" v-if="item.is_status!=3">
						剪辑数量 {{item.video_count}}  <text 
							style="color: #0184F0;margin-left: 20rpx;">{{ '(' + (item.type == 1 ? '老板ip单镜头' : item.type == 2 ? '老板ip多镜头' :item.type == 3? '口播同步':'') + ')' }}</text>
					</view>
					<view class="" style="padding: 0rpx 0rpx 0;" v-if="item.is_status==3">
						<view class="font-overflow" style="color: #FF0000; font-size: 26rpx;width: 400rpx;">
							失败原因：{{item.error_message}}
						</view>



					</view>
					<view class="flex" @click="delWorker(item)" v-if="item.is_status==3">
						<view class="" style="color: #FF3A3A;">
					
							删除
						</view>
					
						<image class="editImg margin-left_10rpx" :src="group3527Sever" mode=""></image>
					
					
					
					</view>
					<view class="flex " v-if="item.is_status!=3">
						<view class="flex" @click="viewWorks(item)" v-if="item.is_status==2">
							<view class="" style="color: #0184F0;">

								作品
							</view>

							<image class="editImg margin-left_10rpx" :src="group3528Sever" mode=""></image>



						</view>
						<view class="flex" @click="viewWorkss(item)" v-else>
							<view class="" style="color: #0184F0;">

								作品
							</view>

							<image class="editImg margin-left_10rpx" :src="group3528Sever" mode=""></image>



						</view>
						<view class="flex margin-left_16rpx margin-right_16rpx" @click="editFn(item)">
							<view class="" style="color: #0184F0;">
								编辑
							</view>

							<image class="editImg margin-left_10rpx" :src="group3182" mode=""></image>

						</view>
						<view class="flex" @click="delWorker(item)" >
							<view class="" style="color: #FF3A3A;">
						
								删除
							</view>
						
							<image class="editImg margin-left_10rpx" :src="group3527Sever" mode=""></image>
						
						
						
						</view>
					</view>


				</view>

				<view class=" flex font-size_24rpx"
					:class="item.is_status==1?'signColorG':item.is_status==2?'signColorP':'signColorR'">
					{{item.is_status==1?'待剪辑':item.is_status==2?'已剪辑':'已失败'}}
				</view>
			</view>
		</mescroll-body>
		<!-- 	<view class="hotSellingList">
			<view class="font-overflow" style="width: 566rpx;font-size: 32rpx;">
				若有一天，你的情绪不能用语言说出来那若有一天，你的情绪不能用语言说出来那
			</view>
			<view class="flex-start-center margin-top_16rpx padding-bottom_40rpx border-bottom-ECECEC">

				<view class="" style="color: #999999;">
					创建时间：2025.10.31 16:00
				</view>
			</view>
			<view class="flex-between" style="padding: 30rpx 0rpx 0;">
				<view class="">
					剪辑数量 0
				</view>
				<view class="flex ">
					<view class="flex">
						<view class="" style="color: #FF3A3A;">

							查看
						</view>

						<image class="editImg margin-left_10rpx" :src="group3183" mode=""></image>



					</view>
					<view class="flex margin-left_16rpx">
						<view class="">
							编辑
						</view>

						<image class="editImg margin-left_10rpx" :src="group3182" mode=""></image>

					</view>
				</view>


			</view>

			<view class="signColorP flex font-size_24rpx">
				待完成
			</view>
		</view> -->

		<uv-tabbar :value="value" @change="changeTabbar" activeColor="#0547fb">
			<uv-tabbar-item text="首页">


				<template v-slot:active-icon>
					<image class="icon" src="/static/eight/蒙版-3.png"></image>
				</template>
				<template v-slot:inactive-icon>
					<image class="icon" src="/static/eight/蒙版-2.png"></image>
				</template>
			</uv-tabbar-item>
			<uv-tabbar-item text="模版中心">
				<template v-slot:active-icon>
					<image class="icon" src="/static/eight/蒙版-1.png"></image>
				</template>
				<template v-slot:inactive-icon>
					<image class="icon" src="/static/eight/蒙版.png"></image>
				</template>
			</uv-tabbar-item>
			<uv-tabbar-item text="任务中心">
				<template v-slot:active-icon>
					<image class="icon" src="/static/eight/蒙版-5.png"></image>
				</template>
				<template v-slot:inactive-icon>
					<image class="icon" src="/static/eight/蒙版-4.png"></image>
				</template>
			</uv-tabbar-item>

		</uv-tabbar>



	</view>
</template>

<script>
	export default {
		data() {
			return {
				group3183: this.$imgs.group3183,
				group3182: this.$imgs.group3182,

				group3528Sever: this.$imgs.group3528Sever,
				group3527Sever: this.$imgs.group3527Sever,

				cIndex: 0,
				value: 2,
				navTop: '',
				materialBg: 'https://tuanma.weijuyunke.com/index/images/material.png',
				tabs: [
					'全部',
					'待剪辑',
					'已剪辑',
					'已失败'
				],
				taskStatis: {},
				list: [],
				hiddenModel: true, //显示影藏
				opacityStyle: 0, //透明度
				heightSystemss: "",
				uid: uni.getStorageSync('uid'),
				memberSetObj: {},
				name:''

			}
		},
		onLoad() {
			const app = getApp();
			this.navTop = app.globalData.navTop;




			if (this.uid) {
				this.taskStatisFn()
				this.createdgetSystemInfo()
				this.userInfos()
			}
			this.refresh()
			this.memberSetFn()


		},
		computed: {


		},
		onPageScroll(ev) {


			if (ev.scrollTop > 10) {
				let opacity = ev.scrollTop / 140

				// this.opacityStyle = opacity > 1 ? 1 : opacity
				this.opacityStyle = 1
				this.hiddenModel = false
				// this.createdgetSystemInfo();

			} else {
				this.hiddenModel = true
			}
		},
		onShow() {


			if (this.uid) {
				this.taskStatisFn()
				this.$nextTick(() => {
					this.mescroll.resetUpScroll();
				});
			}

		},
		methods: {
			changeInput(e){
				console.log(e)
				this.name=e.detail.value
				
				setTimeout(() => {
					this.$nextTick(() => {
						this.mescroll?.resetUpScroll();
					})
				}, 500)
			},
			refresh() {
				if (!uni.getStorageSync('uid')) {
					uni.showModal({
						title: '登录提示',
						content: '请先登录',
						showCancel: false,
						success: (res) => {
							if (res.confirm) {
								uni.switchTab({
									url: `/pages/mine/mine`
								});
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return;
				}
			},
			async userInfos() {
				const result = await this.$http.get({
					url: this.$api.userInfo,
					data: {
						// 用户id
						uid: uni.getStorageSync('uid'),
						// 上级id
						// pid: ''
					}
				});
				if (result.errno == 0) {
					this.user = result.data;

					uni.setStorageSync('user', result.data);


				}
			},
			createdgetSystemInfo() {
				let menuButtonObject = uni.getMenuButtonBoundingClientRect(); //获取菜单按钮（右上角胶囊按钮）的布局位置信息。坐标信息以屏幕左上角为原点。
				uni.getSystemInfo({
					//获取系统信息
					success: res => {
						let navHeight = menuButtonObject.height + (menuButtonObject.top - res
							.statusBarHeight) * 2; //导航栏高度=菜单按钮高度+（菜单按钮与顶部距离-状态栏高度）*2
						this.heightSystemss = navHeight;
						console.log(navHeight, '==========================')

					},
					fail(err) {
						console.log(err);
					}
				});
			},
			viewWorks(item) {
				this.$sun.navGo('/pagesA/creatCenter/piecemeal/piecemealCenterDetail?info=' + encodeURIComponent(JSON
					.stringify({
						...item,
						task_type: 4,
						isTab: true,
					})))

			},
			viewWorkss() {
				this.$sun.toast('剪辑中，请耐心稍等', 'none')
			},
			async memberSetFn() {
				const result = await this.$http.get({
					url: this.$api.memberSet,
					data: {


					}
				});
				if (result.errno == 0) {

					this.memberSetObj = result.data

					console.log(result.data)

				}
			},
			delWorker(obj) {
				uni.showModal({
					title: '提示',
					content: '确定要删除该任务吗?',
					success: async res => {
						if (res.confirm) {

							const result = await this.$http.post({
								url: this.$api.taskDelTemplate,
								data: {
									uid: uni.getStorageSync('uid'),
									id: obj.id,
									
								}
							});
							if (result.errno == 0) {
								this.$sun.toast('删除成功');
								setTimeout(() => {
									this.$nextTick(() => {
										this.mescroll.resetUpScroll();
									});
								}, 2000);
							} else {
								this.$sun.toast(result.message, 'none');
							}
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			editFn(item) {
				console.log(item)

				if (this.user.is_member == 0 && this.memberSetObj.is_open == 1) {
					uni.showModal({
						title: '温馨提示',
						content: '你当前不是会员，请开通会员后享受该功能',
						confirmText: '开通会员',
						confirmColor: '#4A5EFF',
						success: async (res) => {
							if (res.confirm) {


								this.$sun.navGo('/pages/contactUs/memberCenter')

							} else if (res.cancel) {

							}
						}
					});
				} else {
					// 判断是什么类型的 跳什么页面 copyTypeInfo.editType==1?'老板单Ip':copyTypeInfo.editType==2?'老板IP多镜头':'口播同步'

					if (item.type == 1) {
						this.$sun.navGo('/pagesA/creatCenter/creativeList/singleBossIPCreation?objs=' + encodeURIComponent(
							JSON
							.stringify(
								item)))
					} else if (item.type == 2) {
						this.$sun.navGo('/pagesA/creatCenter/creativeList/bossIPCreation?objs=' + encodeURIComponent(JSON
							.stringify(
								item)))
					} else {
						this.$sun.navGo('/pagesA/creatCenter/creativeList/broadcastSynchronization?objs=' +
							encodeURIComponent(
								JSON
								.stringify(
									item)))
					}
				}


			},
			changeTab(e) {
				console.log(e)
				this.cIndex = e
				this.$nextTick(() => {
					this.mescroll.resetUpScroll();
				});
			},

			async upCallback(scroll) {



				const result = await this.$http.post({
					url: this.$api.tempTaskList,
					data: {
						uid: uni.getStorageSync("uid"),




						is_status: this.cIndex == 0 ? '' : this.cIndex,

						page: scroll.num,
						psize: 10,
						name:this.name?this.name:''
					}
				});
				if (result.errno == 0) {

					this.mescroll.endByPage(result.data.list.length, result.data.total);
					if (scroll.num == 1) this.list = [];
					this.list = this.list.concat(result.data.list);
				}

			},
			async taskStatisFn() {
				const result = await this.$http.post({
					url: this.$api.taskStatisTemplate,
					data: {
						uid: uni.getStorageSync("uid"),

					}

				});
				if (result.errno == 0) {
					console.log(result.data)

					this.taskStatis = result.data


				} else {


					this.$sun.toast(result.message)
				}
			},

			navBack() {
				this.$sun.navBack()
			},

			changeTabbar(e) {
				console.log(e)
				if (e == 2) {

				} else if (e == 1) {
					this.$sun.navGo('/pagesA/creatCenter/creativeList/creativeList')
				} else {
					this.$sun.navSwitch('/pages/index/index')
				}

			},

		}
	}
</script>

<style lang="less">
	.v-home-page {
		background-image: (var(--bg-image));
		background-repeat: no-repeat;
		background-size: cover;
		position: relative;
		height: 100vh;
		padding: 20rpx;
		.search-content {
						    margin-top: 35rpx;
							background: #FFFFFF;
						
							// margin-bottom: 30rpx;
						
							
							height: 66rpx;
							border-radius: 230rpx;
						
							image {
								width: 30rpx;
								height: 30rpx;
								margin-right: 10rpx;
							}
						
							view {
								color: #fff;
							}
						
						}

		#barTitle {
			position: fixed;
			width: 750rpx;
			top: 0;
			left: 0;
			background: #fff;
			color: #000000;
			text-align: center;
			font-weight: bold;
			z-index: 9999
		}

		#barTitle>text {
			position: absolute;
			left: 0;
			right: 0;
			bottom: 20rpx
		}



		.icon {
			width: 56rpx;
			height: 56rpx;
		}

		.taskStatistics {
			margin-top: 28rpx;
			width: 709rpx;
			height: 154.88rpx;
			padding: 30rpx;

			border-radius: 20rpx;

			box-shadow: 0rpx 2rpx 8rpx 0rpx rgba(1, 132, 240, 0.05);
			background: rgb(255, 255, 255);
		}



		.hotSellingList {
			margin-top: 30rpx;
			padding: 20rpx;
			border-radius: 20rpx;
			position: relative;
			background: rgb(255, 255, 255);
			width: 709.7rpx;


			.yellowBtn {
				width: 77.92rpx;
				height: 40rpx;
				border-radius: 10rpx;
				background: linear-gradient(180.00deg, rgb(255, 229, 101), rgb(255, 241, 156) 100%);
			}

			.waterBtn {
				border-radius: 10rpx;
				width: 77.92rpx;
				height: 40rpx;
				background: linear-gradient(180.00deg, rgb(178, 246, 255), rgb(158, 223, 255) 100%);
			}

			.editImg {
				width: 32.18rpx;
				height: 32.18rpx;
			}

			.signColorG {
				color: #fff;
				width: 104rpx;
				height: 52rpx;
				border-radius: 0rpx 20rpx 0rpx 20rpx;
				position: absolute;
				background: rgb(17, 216, 65);
				right: 0;
				top: 0;
			}

			.signColorP {
				color: #fff;
				width: 104rpx;
				height: 52rpx;
				border-radius: 0rpx 20rpx 0rpx 20rpx;
				position: absolute;
				background: #4EAFFF;
				right: 0;
				top: 0;
			}

			.signColorR {
				color: #fff;
				width: 104rpx;
				height: 52rpx;
				border-radius: 0rpx 20rpx 0rpx 20rpx;
				position: absolute;
				background: #FF0000;
				right: 0;
				top: 0;
			}
		}
	}
</style>